<template>
  <d2-container :class="{ 'page-compact': crud.pageOptions.compact }">
    <d2-crud-x
      ref="d2Crud"
      v-bind="_crudProps"
      v-on="_crudListeners"
      @deviceUpgrade="deviceUpgrade"
      @upgradeLogging="upgradeLogging"
    >
      <div slot="header">
        <crud-search
          ref="search"
          :options="crud.searchOptions"
          @submit="handleSearch"
        />
        <crud-toolbar
          :search.sync="crud.searchOptions.show"
          :compact.sync="crud.pageOptions.compact"
          :columns="crud.columns"
          @refresh="doRefresh()"
          @columns-filter-changed="handleColumnsFilterChanged"
        />
      </div>
      <template slot="download_urlSlot" slot-scope="scope">
        <el-link :href="scope.row.download_url" type="primary" target="_blank">下载</el-link>
      </template>
    </d2-crud-x>
    <!--  设备更新进度  -->
    <el-drawer
      :visible.sync="deviceUpgradeDrawer"
      :size="900">
      <div slot="title">
        <span>设备更新进度</span>
        <el-tag size="small" style="margin-left: 10px">{{deviceManageRow.device_id}}</el-tag>
      </div>
      <app-device-device-upgrade style="margin-top: 80px;margin-left: 10px" :deviceManageId="deviceManageRow.id"></app-device-device-upgrade>
    </el-drawer>
    <!--  升级日志  -->
    <el-drawer
      :visible.sync="upgradeLoggingDrawer"
      :size="900">
      <div slot="title">
        <span>升级日志</span>
        <el-tag size="small" style="margin-left: 10px">{{deviceManageRow.device_id}}</el-tag>
      </div>
      <app-device-upgrade-logging style="margin-top: 80px;margin-left: 10px" :deviceManageId="deviceManageRow.id"></app-device-upgrade-logging>
    </el-drawer>
  </d2-container>
</template>

<script>
import * as api from './api'
import { crudOptions } from './crud'
import { d2CrudPlus } from 'd2-crud-plus'
import AppDeviceDeviceUpgrade from "@/views/plugins/dvadmin-upgrade-center-web/src/appDeviceManage/deviceUpgrade/index";
import AppDeviceUpgradeLogging
  from "@/views/plugins/dvadmin-upgrade-center-web/src/appDeviceManage/upgradeLogging/index";
export default {
  name: 'appDeviceManage',
  components: {AppDeviceUpgradeLogging, AppDeviceDeviceUpgrade},
  mixins: [d2CrudPlus.crud],
  data () {
    return {
      deviceManageRow: {},
      // 设备更新进度值
      deviceUpgradeDrawer: false,
      // 升级日志
      upgradeLoggingDrawer:false
    }
  },
  methods: {
    getCrudOptions () {
      return crudOptions(this)
    },
    pageRequest (query) {
      return api.GetList(query)
    },
    addRequest (row) {
      return api.createObj(row)
    },
    updateRequest (row) {
      return api.UpdateObj(row)
    },
    delRequest (row) {
      return api.DelObj(row.id)
    },
    // 设备更新进度
    deviceUpgrade (scope) {
      this.deviceUpgradeDrawer =true
      this.deviceManageRow = scope.row
    },
    // 升级日志
    upgradeLogging (scope) {
      this.upgradeLoggingDrawer =true
      this.deviceManageRow = scope.row
    }
  }
}
</script>
